package com.zhonggong.empProducer.service.impl;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.List;

import com.zhonggong.network.emp.model.Emp;

public class Serialize {
	/**
	 * 列表序列化（用于Redis整存整取）
	 * @param computerList
	 * @return
	 */
	public byte[] serialize(List<Emp> empsList) {
		if (empsList == null) {
			throw new NullPointerException("集合不为空！");
		}
		byte[] rv=null;
		ByteArrayOutputStream bos = null;
		ObjectOutputStream os = null;
		try {
			bos = new ByteArrayOutputStream();
			os = new ObjectOutputStream(bos);
			for(Emp obj : empsList){
				os.writeObject(obj);
			}
			os.writeObject(null);
			os.close();
			bos.close();
			rv = bos.toByteArray();
		} catch (IOException e) {
			throw new IllegalArgumentException("序列化异常！", e);
		}
		return rv;
	}
}
